﻿using System;
using System.Net;

namespace NCMIS.ObjectModel.Rest
{
    /// <summary>
    /// Contains the mapped values of CMIS service exceptions to HTTP status codes.
    /// </summary>
    public static class ServiceException
    {
        #region Common CMIS Exceptions

        /// <summary>
        /// Represents the HTTP status 400. Equivalent to the <see cref="System.Net.HttpStatusCode.BadRequest"/>.
        /// InvalidArgument is sent when one or more of the input parameters to the sevice method is missing or invalid.
        /// </summary>
        public const HttpStatusCode InvalidArgument = HttpStatusCode.BadRequest;
        /// <summary>
        /// Represents the HTTP status 404. Equivalent to the <see cref="System.Net.HttpStatusCode.NotFound"/>.
        /// ObjectNotFound is sent when the service call has specified an object that does nor exist in the repository.
        /// </summary>
        public const HttpStatusCode ObjectNotFound = HttpStatusCode.NotFound;
        /// <summary>
        /// Represents the HTTP status 403. Equivalent to the <see cref="System.Net.HttpStatusCode.NotFound"/>.
        /// ObjectNotFound is sent when the service call has specified an object that does nor exist in the repository.
        /// </summary>
        public const HttpStatusCode PermissionDenied = HttpStatusCode.Forbidden;
        /// <summary>
        /// Represents the HTTP status 405. Equivalent to the <see cref="System.Net.HttpStatusCode.MethodNotAllowed"/>.
        /// PermissionDenied is sent when the caller of the service method does not have sufficient permissions to perform the operation.
        /// </summary>
        public const HttpStatusCode OperationNotSupported = HttpStatusCode.MethodNotAllowed;
        /// <summary>
        /// Represents the HTTP status 500. Equivalent to the <see cref="System.Net.HttpStatusCode.InternalServerError"/>.
        /// Runtime is sent as a reposnse to any other error cause that is not expressible by another CMIS exception.
        /// </summary>
        public const HttpStatusCode Runtime = HttpStatusCode.InternalServerError;

        #endregion

        #region Other Exceptions

        /// <summary>
        /// Represents the HTTP status 409. Equivalent to the <see cref="System.Net.HttpStatusCode.Conflict"/>.
        /// Constraint is sent when the operation violates a repository- or object-level constraint defined in the CMIS domain model.
        /// </summary>
        public const HttpStatusCode Constraint = HttpStatusCode.Conflict;
        /// <summary>
        /// Represents the HTTP status 409. Equivalent to the <see cref="System.Net.HttpStatusCode.Conflict"/>.
        /// ContentAlreadyExists is sent when the the method is trying to set the content stream for a Document that already has a content stream,
        /// without explicitly specifying the overwriteFlag.
        /// </summary>
        public const HttpStatusCode ContentAlreadyExists = HttpStatusCode.Conflict;
        /// <summary>
        /// Represents the HTTP status 400. Equivalent to the <see cref="System.Net.HttpStatusCode.BadRequest"/>.
        /// FilterNotValid is sent when the property or rendition filter input to the method is not valid.
        /// </summary>
        public const HttpStatusCode FilterNotValid = HttpStatusCode.BadRequest;
        /// <summary>
        /// Represents the HTTP status 409. Equivalent to the <see cref="System.Net.HttpStatusCode.Conflict"/>.
        /// NameConstraintViolation is sent when the repository is not able to store the object that the user is creating/udating due to name constraint violation.
        /// </summary>
        public const HttpStatusCode NameConstraintViolation = HttpStatusCode.Conflict;
        /// <summary>
        /// Represents the HTTP status 500. Equivalent to the <see cref="System.Net.HttpStatusCode.InternalServerError"/>.
        /// Storage is sent when the repository is not able to store the object that the user is creating/updating due to an internal storage problem.
        /// </summary>
        public const HttpStatusCode Storage = HttpStatusCode.InternalServerError;
        /// <summary>
        /// Represents the HTTP status 403. Equivalent to the <see cref="System.Net.HttpStatusCode.Forbidden"/>.
        /// StreamNotSupported is sent when the method is trying to get or set a ContentStream for a Document whose object-type specifies that a content
        /// stream is not allowed for Documents of that type.
        /// </summary>
        public const HttpStatusCode StreamNotSupported = HttpStatusCode.Forbidden;
        /// <summary>
        /// Represents the HTTP status 409. Equivalent to the <see cref="System.Net.HttpStatusCode.Conflict"/>.
        /// UpdateConflict is sent when the method is trying to upate an object which is no longer current.
        /// </summary>
        public const HttpStatusCode UpdateConflict = HttpStatusCode.Conflict;
        /// <summary>
        /// Represents the HTTP status 409. Equivalent to the <see cref="System.Net.HttpStatusCode.Conflict"/>.
        /// Versioning is sent when the repository is trying to perform an action, on a non-current version of a Document, that cannot be performed
        /// on a non-current version.
        /// </summary>
        public const HttpStatusCode Versioning = HttpStatusCode.Conflict;

        #endregion
    }
}
